﻿Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Credits
    Inherits System.Windows.Forms.UserControl

    Dim parser As New Parser()
    Private secText As New List(Of TransparentRichTextBox)
    Private tmp As String
    Private isFullScreen As Boolean = False
    Private jnsAnim As jnsAnimasi = jnsAnimasi.Slide_Up
    Private pathSound As String
    Private pathMedia As String
    Private pilihMedia As Integer
    Private full As Form
    Private cred As Control()
    Private imgList As New List(Of String)

    Private posX As Integer = Me.Size.Width
    Private posY As Integer = Me.Size.Height
    Private timeSlide As New Integer
    Private imgSpd As New Integer

    Private tR As Integer
    Private tG As Integer
    Private tB As Integer

    Dim indx As Integer

    Dim aR As Integer
    Dim aG As Integer
    Dim aB As Integer

    Dim kembali As Boolean = False

    'UserControl1 overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Credits))
        Me.PictureBox1 = New System.Windows.Forms.PictureBox()
        Me.tmrScroll = New System.Windows.Forms.Timer(Me.components)
        Me.player = New AxWMPLib.AxWindowsMediaPlayer()
        Me.tmrLR = New System.Windows.Forms.Timer(Me.components)
        Me.tmrBl = New System.Windows.Forms.Timer(Me.components)
        Me.tmrPic = New System.Windows.Forms.Timer(Me.components)
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.player, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'PictureBox1
        '
        Me.DoubleBuffered = True
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
        Me.PictureBox1.Location = New System.Drawing.Point(223, 145)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(155, 117)
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.PictureBox1.TabIndex = 1
        Me.PictureBox1.TabStop = False
        '
        'tmrScroll
        '
        Me.tmrScroll.Enabled = True
        Me.tmrScroll.Interval = 10
        '
        'player
        '
        Me.player.Enabled = True
        Me.player.Location = New System.Drawing.Point(223, 145)
        Me.player.Name = "player"
        Me.player.OcxState = CType(resources.GetObject("player.OcxState"), System.Windows.Forms.AxHost.State)
        Me.player.Size = New System.Drawing.Size(155, 117)
        Me.player.TabIndex = 2
        Me.player.Visible = False
        '
        'tmrLR
        '
        Me.tmrLR.Interval = 1000
        '
        'tmrBl
        '
        Me.tmrBl.Enabled = True
        Me.tmrBl.Interval = 10
        '
        'tmrPic
        '
        '
        'Credits
        '
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None
        Me.Controls.Add(Me.PictureBox1)
        Me.Controls.Add(Me.player)
        Me.Name = "Credits"
        Me.Size = New System.Drawing.Size(397, 274)
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.player, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

    Public Sub goFullScreen(ByVal isFullScreen As Boolean)
        If isFullScreen Then
            full = New Form
            full.Name = "frmFullscreen"
            full.FormBorderStyle = FormBorderStyle.None
            full.ShowInTaskbar = False
            full.WindowState = FormWindowState.Maximized


            Dim ctrl As New Credits

            full.Controls.Add(ctrl)
            ctrl.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top
            ctrl.BackColor = Me.BackColor
            ctrl.ForeColor = Me.ForeColor
            ctrl.MediaPath = pathMedia
            ctrl.CreditText = tmp
            ctrl.Animation = jnsAnim
            ctrl.ScrollSpeed = Me.ScrollSpeed
            ctrl.Media = Me.Media
            ctrl.Sounds = Me.Sounds
            ctrl.Font = Me.Font
            ctrl.player.URL = pathMedia

            Dim quit As New Label

            quit.ForeColor = System.Drawing.Color.White
            quit.BackColor = System.Drawing.Color.Gray
            quit.Text = "Press (ESC) to exit fullscreen"
            quit.Location = New System.Drawing.Point(1, 2)
            quit.AutoSize = True
            full.Controls.Add(quit)
            quit.BringToFront()
            AddHandler full.FormClosing, AddressOf full_FormClosing
            AddHandler full.KeyDown, AddressOf full_KeyDown
            full.KeyPreview = True
            full.Show()
        Else

            If (IsNothing(full) = False) Then
                full.Hide()
                full.Dispose()
            End If
        End If
    End Sub

    <System.ComponentModel.Description("Switch to full screen mode. (F9) to activate Fullscreen, (ESC) to close fullscreen.")> _
    Property FullScreen() As Boolean
        Get
            Return isFullScreen
        End Get
        Set(ByVal value As Boolean)
            isFullScreen = value
            goFullScreen(isFullScreen)
        End Set
    End Property

    Private Sub full_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs)
        isFullScreen = False
    End Sub

    Private Sub full_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If (e.KeyCode = 27) Then
            full.Close()
        End If
    End Sub

    <System.ComponentModel.Description("Set scrolling speed")> _
    Property ScrollSpeed() As Integer
        Get
            Return tmrScroll.Interval
        End Get
        Set(ByVal value As Integer)
            tmrScroll.Interval = value
            tmrBl.Interval = value
            tmrLR.Interval = value
            tmrPic.Interval = value * 10
        End Set
    End Property

    <System.ComponentModel.Description("Set image transition speed")> _
    Property imageSpeed() As Integer
        Get
            Return imgSpd
        End Get
        Set(ByVal value As Integer)
            imgSpd = value
        End Set
    End Property

    Private Sub SlideUp() Handles tmrScroll.Tick
        timeSlide = timeSlide + 1
        Credit.Top = posY
        posY = posY - 10
        If (posY < -Me.Size.Height) Then
            posY = Me.Height
        End If

        If timeSlide = imgSpd And pilihMedia = 0 And jnsAnim = 3 And imgList.Count > 0 Then
            timeSlide = 0
            If indx = imgList.Count - 1 Then
                PictureBox1.ImageLocation = imgList.Item(indx)
                indx = 0
            Else
                PictureBox1.ImageLocation = imgList.Item(indx)
                indx = indx + 1
            End If
        ElseIf timeSlide = imgSpd And pilihMedia <> 0 And jnsAnim <> 3 And imgList.Count = 0 Then
            timeSlide = 0
        End If

    End Sub

    Private Sub Left_Right() Handles tmrLR.Tick
        Credit.Left = posX
        posX = posX - 10
        If (posX < -Me.Size.Width) Then
            posX = Me.Size.Width
            If indx = secText.Count Then
                Credit.Clear()
                Credit.Text = secText.Item(0).Text
                'MessageBox.Show(Credit.Text)
                indx = 1
                parser.P_Title(Credit, Credit.Text)
            Else
                Credit.Clear()
                Credit.Text = secText.Item(indx).Text
                'MessageBox.Show(Credit.Text)
                indx = indx + 1
                parser.P_Title(Credit, Credit.Text)
            End If
        End If
    End Sub

    Public Overrides Property BackColor As System.Drawing.Color
        Get
            Return MyBase.BackColor
        End Get
        Set(ByVal value As System.Drawing.Color)
            MyBase.BackColor = value
            Credit.BackColor = value
        End Set
    End Property

    Public Overrides Property ForeColor As System.Drawing.Color
        Get
            Return MyBase.ForeColor
        End Get
        Set(ByVal value As System.Drawing.Color)
            MyBase.ForeColor = value
            Credit.ForeColor = value
        End Set
    End Property

    Public Sub fadein()

        If (aR < tR And aR < 256) Then
            aR += 1
        ElseIf (aR > tR And aR > -1) Then
            aR -= 1
        End If

        If (aG < tG And aG < 256) Then
            aG += 1
        ElseIf (aG > tG And aG > -1) Then
            aG -= 1
        End If

        If (aB < tB And aB < 256) Then
            aB += 1
        ElseIf (aB > tB And aB > -1) Then
            aB -= 1
        End If

    End Sub

    Public Sub fadeout()
        '
        If (aR < Credit.ForeColor.R And aR < 256) Then
            aR += 1

        ElseIf (aR > -1 And aR > Credit.ForeColor.R) Then
            aR -= 1

        End If

        If (aG < Credit.ForeColor.G And aG < 256) Then
            aG += 1

        ElseIf (aG > -1 And aG > Credit.ForeColor.G) Then
            aG -= 1

        End If

        If (aB < Credit.ForeColor.B And aB < 256) Then
            aB += 1

        ElseIf (aB > -1 And aB > Credit.ForeColor.B) Then
            aB -= 1

        End If

    End Sub

    Private Sub Blink() Handles tmrBl.Tick
        Credit.TabStop = False
        If (kembali = True And Me.BackColor.ToArgb <> Color.FromArgb(tR, tG, tB).ToArgb) Then
            fadein()
        ElseIf (Color.FromArgb(aR, aG, aB).ToArgb = Credit.ForeColor.ToArgb) Then
            kembali = True

            If indx = secText.Count Then
                Credit.Clear()
                Credit.Text = secText.Item(0).Text
                parser.P_Title(Credit, Credit.Text)
                indx = 1
            Else
                Credit.Clear()
                Credit.Text = secText.Item(indx).Text
                parser.P_Title(Credit, Credit.Text)
                indx += 1
            End If
        Else
            If (kembali = True And Me.BackColor.ToArgb = Color.FromArgb(tR, tG, tB).ToArgb) Then
                tmrBl.Enabled = False
                Threading.Thread.Sleep(3000)
                tmrBl.Enabled = True
            End If

            fadeout()
            kembali = False
        End If
        Me.BackColor = Color.FromArgb(aR, aG, aB)

    End Sub


    Public Sub fun(ByVal enums)

        tR = Me.BackColor.R
        tG = Me.BackColor.G
        tB = Me.BackColor.B
        Select Case enums
            Case 0
                tmrScroll.Enabled = True
                tmrBl.Enabled = False
                tmrLR.Enabled = False

                Me.PictureBox1.Visible = False
                Me.player.Visible = False

                posY = Me.Size.Height

                Credit.Left = 0
                Credit.Clear()
                parser.ukuranWindowH = Me.Size.Height
                parser.ukuranWindowW = Me.Size.Width
                If (String.IsNullOrEmpty(tmp) <> True) Then
                    'parser.parsingText(secText, tmp)
                    Credit.Text = secText.Item(0).Text
                    parser.P_Title(Credit, Credit.Text)
                End If

                Credit.SelectAll()
                Credit.SelectionAlignment = HorizontalAlignment.Center
                Credit.DeselectAll()

                timeSlide = 0
                SlideUp()
            Case 1
                tmrScroll.Enabled = False
                tmrBl.Enabled = False
                tmrLR.Enabled = True

                Me.PictureBox1.Visible = False
                Me.player.Visible = False

                posX = Me.Size.Width
                parser.ukuranWindowH = Me.Size.Height
                parser.ukuranWindowW = Me.Size.Width
                If (String.IsNullOrEmpty(tmp) <> True) Then
                    If (parser.parsingText(secText, tmp)) Then
                        Credit.Clear()
                        Credit.BorderStyle = Windows.Forms.BorderStyle.None
                        Credit.Text = secText.Item(0).Text
                        parser.P_Title(Credit, Credit.Text)
                        Credit.Top = (Me.Size.Height / 3)
                        indx = 1
                        Left_Right()
                    End If
                End If
            Case 2
                tmrScroll.Enabled = False
                tmrBl.Enabled = True
                tmrLR.Enabled = False

                Me.PictureBox1.Visible = False
                Me.player.Visible = False

                aR = Credit.ForeColor.R
                aG = Credit.ForeColor.G
                aB = Credit.ForeColor.B

                Credit.Top = Me.Size.Height / 3
                Credit.Left = 0

                Credit.Clear()
                Credit.BorderStyle = Windows.Forms.BorderStyle.None
                If (String.IsNullOrEmpty(tmp) <> True) Then
                    Credit.Text = secText.Item(0).Text
                    indx = 0
                    parser.ukuranWindowH = Me.Size.Height
                    parser.ukuranWindowW = Me.Size.Width
                    parser.P_Title(Credit, Credit.Text)
                End If

                Credit.TabStop = False
                Credit.ReadOnly = False

            Case 3
                tmrScroll.Enabled = True
                tmrBl.Enabled = False
                tmrLR.Enabled = False

                posY = Me.Size.Height

                Credit.Clear()
                Credit.BorderStyle = Windows.Forms.BorderStyle.None
                parser.ukuranWindowH = Me.Size.Height
                parser.ukuranWindowW = Me.Size.Width
                If (String.IsNullOrEmpty(tmp) <> True) Then
                    parser.parsingText(secText, tmp)
                    Credit.Text = secText.Item(0).Text
                    parser.P_Title(Credit, Credit.Text)
                End If

                Credit.SelectAll()
                Credit.SelectionAlignment = HorizontalAlignment.Left
                Credit.DeselectAll()

                indx = 1
                Credit.Left = Me.Size.Width / 15

                If pilihMedia = 0 Then
                    PictureBox1.Visible = True
                    player.Visible = False
                ElseIf pilihMedia = 1 Then
                    PictureBox1.Visible = False
                    player.Visible = True
                End If

                If (parser.parsImg(imgList, pathMedia)) Then
                    PictureBox1.ImageLocation = imgList.Item(0)
                End If
                timeSlide = 0
                SlideUp()
        End Select
    End Sub

    Public Enum jnsAnimasi
        Slide_Up = 0
        Left_Right = 1
        Fade = 2
        Mix = 3
    End Enum

    <System.ComponentModel.Description("Select animation type")> _
    Property Animation As jnsAnimasi
        Get
            Return jnsAnim
        End Get
        Set(ByVal value As jnsAnimasi)
            jnsAnim = value
            Me.Refresh()
            fun(jnsAnim)
        End Set
    End Property

    Public Enum jnsMedia
        Image = 0
        Video = 1
    End Enum

    <System.ComponentModel.Description("Add media either video or picture, only for mix animation.")> _
    Property Media As jnsMedia
        'video / gambar
        Get
            Return pilihMedia
        End Get
        Set(ByVal value As jnsMedia)
            pilihMedia = value
            If (pilihMedia = 0 And jnsAnim = 3 And imgList.Count > 0) Then
                parser.parsImg(imgList, pathMedia)
                PictureBox1.ImageLocation = imgList.Item(0)
                PictureBox1.Visible = True
                player.Visible = False
            ElseIf (pilihMedia = 1 And jnsAnim = 3) Then
                player.URL = pathMedia
                player.Visible = True
                PictureBox1.Visible = False
                pathSound = ""
            End If
        End Set
    End Property

    <System.ComponentModel.Description("Add music as backsound")> _
    Property Sounds As String   'back music
        Get
            Return pathSound
        End Get
        Set(ByVal value As String)
            player.URL = value
            pathSound = value
        End Set
    End Property

    <System.ComponentModel.Description("Add credit text, supported tag : <section></section><title></title><br>")> _
    Property CreditText As String
        Get
            Return tmp
        End Get
        Set(ByVal value As String)
            tmp = value
            parser.parsingText(secText, value)
            fun(jnsAnim)
        End Set
    End Property

    <System.ComponentModel.Description("Path to media file")> _
    Property MediaPath As String
        Get
            Return pathMedia
        End Get
        Set(ByVal value As String)
            pathMedia = value
            If pilihMedia = 0 & jnsAnim = 3 Then
                parser.parsImg(imgList, pathMedia)
                PictureBox1.ImageLocation = imgList.Item(0)
                PictureBox1.Visible = True
                player.Visible = False
            ElseIf (pilihMedia = 1 & jnsAnim = 3) Then
                player.URL = pathMedia
            End If
            Me.Refresh()
        End Set
    End Property



    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents tmrScroll As System.Windows.Forms.Timer
    Friend WithEvents player As AxWMPLib.AxWindowsMediaPlayer
    Friend WithEvents tmrLR As System.Windows.Forms.Timer
    Friend WithEvents tmrBl As System.Windows.Forms.Timer
    Friend WithEvents tmrPic As System.Windows.Forms.Timer

End Class
